# -*- coding: utf-8 -*-
from django import template
from cms.models.pagemodel import Page
from catalog.models import *

register = template.Library()

def cms_navigation(title_page):
    cms_pages = Page.objects.filter(in_navigation=True, published=True)
    section=Section.objects.all()
    category=Category.objects.all()
    title_page = title_page.split(' - ')
    context = {'cms_pages': cms_pages,
               'section': section,
               'category': category,
               'title_page': title_page[0],
               }
    try:
        context.update({'title_down': title_page[1]})
        return context
    except:
        return context

register.inclusion_tag('main-navigation.html')(cms_navigation)

@register.filter
def get_items(self):
    return self.items()

@register.filter
def get_sec(self):
    return self[0].id_cat.id_sec.name

@register.filter
def get_cat(self):
    return self[0].id_cat.name